using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum BulletType
{ 
       player=0,
       Enemy=1,
}

public class Bullet : MonoBehaviour
{
    public float speed = 2f;
    public Vector3 direction = new Vector3(0, 1, 0);

    public BulletType bulletType = BulletType.player;
    public float damageValue = 1f;
    
    // Start is called before the first frame update
    void Start()
    {
        if (bulletType == BulletType.player)
        {
            this.GetComponent<AudioSource>().Play();

        }
    }

    // Update is called once per frame
    void Update()
    {
        this.transform.Translate(direction * speed * Time.deltaTime);
    }

    void OnTriggerEnter2D(Collider2D collider)
    {
        if (bulletType == BulletType.player) 
        {
            if (collider.gameObject.CompareTag("Enemy"))
            {
                collider.gameObject.SendMessage("BeHit",damageValue);

                Destroy(this.gameObject);
                
                GameManager.gameManager_Instance.GameOverp();
            }
            if (collider.gameObject.CompareTag("Boss"))
            {
                if (GameManager.gameManager_Instance.bossbool)
                {
                    collider.gameObject.SendMessage("BeHit", damageValue);
                    FSM.FSM_Instance.ming = true;
                }
            }
            if (collider.gameObject.CompareTag("Wall"))
            {
                
                Destroy(collider.gameObject);
                Destroy(this.gameObject);
            }

            if (collider.gameObject.CompareTag("AriWall"))
            {

                
                Destroy(this.gameObject);
            }

            if (collider.gameObject.CompareTag("Walls"))
            {

                
                Destroy(this.gameObject);
            }


        }
        if (bulletType == BulletType.Enemy)
        {
            if (collider.gameObject.CompareTag("Player"))
            {
                collider.gameObject.SendMessage("BeHit", damageValue);

                Destroy(this.gameObject);
                if (!tankstart.tankstart_Instance.Startwo)
                {
                    GameManager.gameManager_Instance.GameOver();
                }
                if (tankstart.tankstart_Instance.Startwo)
                {
                    GameManager.gameManager_Instance.GameOvers();
                }
                
            }

            if (collider.gameObject.CompareTag("Wall"))
            {

                Destroy(collider.gameObject);
                Destroy(this.gameObject);
            }
            if (collider.gameObject.CompareTag("Bullet"))
            {

                Destroy(collider.gameObject);
                Destroy(this.gameObject);
            }

            if (collider.gameObject.CompareTag("AriWall"))
            {


                Destroy(this.gameObject);
            }

            if (collider.gameObject.CompareTag("Walls"))
            {


                Destroy(this.gameObject);
            }
        }


    }

}
